package com.edoovo.loginservice.application.config.auth;

import lombok.Builder;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.edoovo.loginservice.application.domain.UserStatus;

import java.time.LocalDateTime;
import java.util.Collection;

@Data
@Builder
public class CustomUserDetails implements UserDetails {

    private static final long serialVersionUID = 1713833368779688621L;

    private String id;
    private String username;
    private String password;
    private String role;
    private UserStatus userStatus;
    private LocalDateTime currentLoginDate;
    private Collection<GrantedAuthority> authorities ;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return UserStatus.ACTIVE == userStatus;
    }

    @Override
    public boolean isAccountNonLocked() {
        return UserStatus.ACTIVE == userStatus;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return UserStatus.ACTIVE == userStatus;
    }

    @Override
    public boolean isEnabled() {
        return UserStatus.ACTIVE == userStatus;
    }
}
